layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;
			//刷新表单的复选框
		setTimeout(function(){
				$(".userGrade").get(0)[1].selected=true;//会员等级
				form.render('select');
		},100);
		
    form.on("submit(addUser)",function(data){
		var userid=$(".userId").text()
		var user_Data={
			'account':$(".userName").val(),
			'pwd':$(".userPwd").val(),
			'gender':data.field.sex,	//性别
			'email':$(".userEmail").val(), //邮箱
			'autograph':$(".userDesc").val(), //个性签名
			'role':data.field.userGrade,
			'type':data.field.userStatus,
			'userId':userid
		}
		var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
		
		if(userid!=""){
			Vue.http.post(global_url+'/admin/updateUser',user_Data).then(
				response=>{
						top.layer.close(index);
						layer.closeAll("iframe");
						top.layer.msg(response.body.datas);
						//刷新父页面
						parent.location.reload();
						
				},
				response=>{
					top.layer.close(index);
					layer.closeAll("iframe");
					top.layer.msg(response.body.datas);
					//刷新父页面
					parent.location.reload();
				}
			);
					
		}else{
			Vue.http.post(global_url+'/admin/insert',user_Data).then(
					response=>{
						top.layer.close(index);
						layer.closeAll("iframe");
						if(response.data.code=='-1'){
							layer.msg(response.data.msg);
							return
						}
						top.layer.msg("用户添加成功！");
						//刷新父页面
						parent.location.reload();
						
					},					
					response=>{
						top.layer.close(index);
						layer.closeAll("iframe");
						top.layer.msg("用户添加失败！");
						//刷新父页面
						parent.location.reload();
						console.log(response.body)
						
					}
			
			);
		}
		
        return false;
    })

    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    //定时发布
    var time = new Date();
    var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());

})